var server = require('utils/server.js');
App({
    onLaunch: function() {
        // 展示本地存储能力
        var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)
        // 登录
        wx.login({
            success: res => {
                // 发送 res.code 到后台换取 openId, sessionKey, unionId
                let data = {
                    code: res.code,
                    pid: getApp().globalData.pid,
                }
                server.sendPost('wxuser/wxuser', data).then(res => {
                    if (res.status == 1) {
                        getApp().globalData.openid = res.wxuser.openid;
                        getApp().globalData.tel = res.wxuser.phone;
                        getApp().globalData.employId = '成功';
                        if (this.employIdCallback) {
                            this.employIdCallback('成功');
                        }
                    }
                })
            }
        })
    },
    globalData: {
        userInfo: null,
        section: [{
            name: '项目展示',
            typeId: '1'
        }, {
            name: '户型展示',
            typeId: '2'
        }, {
            name: '项目品鉴',
            typeId: '3'
        }, {
            name: '在线咨询',
            typeId: '4'
        }, {
            name: '在线订购',
            typeId: '5'
        }],
        aroundList: [{
                name: '交通',
                id: '150000',
                url: '../../images/icon/icon-jt.png',
                iconPath: '../../images/icon/icon-jiaotong1.png',
            },
            {
                name: '教育',
                id: '140000',
                url: '../../images/icon/icon-jy.png',
                iconPath: '../../images/icon/icon-jiaoyu1.png',
            },
            {
                name: '医疗',
                id: '090000',
                url: '../../images/icon/icon-yl.png',
                iconPath: '../../images/icon/icon-yiyuan1.png',

            },
            {
                name: '购物',
                id: '060000',
                url: '../../images/icon/icon-gw.png',
                iconPath: '../../images/icon/icon-gouwu1.png',
            },
            {
                name: '公园',
                id: '110000',
                url: '../../images/icon/icon-gy.png',
                iconPath: '../../images/icon/icon-park1.png',
            }
        ],
        key: '5d52a4b3061cabc57a441a17ac72cc8e',
        showHint: showHint,
        handleTap: handleTap,
        sendPost:server.sendPost,
        qian_img:'https://jzy.nuoche.la/',//图片前缀
        openid:'',
        tel:'',
        pid:'34',//楼盘id 
        API:'https://jzy.nuoche.la/v1/',
        employId:'',
        throttle:throttle
    },
})
function throttle(fn, gapTime) {
    if (gapTime == null || gapTime == undefined) {
        gapTime = 1500
    }

    let _lastTime = null
    return function () {
        let _nowTime = + new Date()
        if (_nowTime - _lastTime > gapTime || !_lastTime) {
            fn()
            _lastTime = _nowTime
        }
    }
}
function showHint(msg) {
    wx.showToast({
        title: msg,
        icon: "none"
    })
}
//点击每个导航的点击事件
function handleTap(e) {
    var id = e.currentTarget.id;
    this.setData({
        currentId: id
    })
    if (id == 1) {
        wx.navigateTo({
            url: '../index/index'
        })
    } else if (id == 2) {
        wx.redirectTo({
            url: '../huxing/index'
        })
    } else if (id == 3) {
        wx.redirectTo({
            url: '../buchongxinxi/index'
        })
    } else if (id == 4) {
        wx.redirectTo({
            url: '../seller/index'
        })
    } else if (id == 5) {
        wx.redirectTo({
            url: '../payPlan/index'
        })
    }
}
// "plugins": {
//     "contactPlugin": {
//         "version": "1.3.0",
//         "provider": "wx104a1a20c3f81ec2"
//     }
// }